

import java.text.DecimalFormat;
import Javabeans.DatPoint;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Random;
import knn.KNN_1;
import static java.lang.System.out;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * @author Muhammed
 * 
 */
public class Main {
    public static void main(String[] args) throws FileNotFoundException, IOException, CloneNotSupportedException {
        String path = "src/data/";
        
        String testProdSelData="testProdSelection.csv";
        String trainProdSelData="prodsel.csv";

        String testProdIntroData = "testProdIntro.binary.csv";
        String trainProdIntroData = "trainProdIntro.binary.csv";

        String data1[] = {"librarian","spend>>saving","48","35","20","2","C4"};
        String data2[] = {"student","spend<<saving","10","15","12","3","C1"};
        String data3[] = {"librarian","spend>>saving","48","35","20","2","C4"};

        DatPoint dp = new DatPoint(data1);
        DatPoint dp1 = new DatPoint(data3);


        KNN_1 knn = new KNN_1();
        knn.loadTraining(path, trainProdSelData);
        //knn.loadTesting(path, testProdIntroData);
        knn.setOutputAttribute(7);
        double weights[] = {1,1,1,1,1,1};//{1,1,1,1,1,1,1,1};//{1,1,10,2.5,1,1,0.5,2.8};//{1,1,2,10,4,9}
        knn.setWeights(weights);
        //knn.normalizeTrainingDataSet();
        //knn.predictTestingSet(5, true, true);
        knn.crossValidate(160, 5, false, false);


    }
    
    public static void roundRobin(String path, String trainProdSelData, int outputAttribute) throws IOException, CloneNotSupportedException{
        double oldPrecision, newPrecision;

        KNN_1 knn = new KNN_1();
        knn.loadTraining(path, trainProdSelData);
        knn.setOutputAttribute(outputAttribute);
        newPrecision=knn.crossValidate(186, 3, false, false);
        out.println("\tAverage Precision: "+newPrecision);

        double n=0.5;
        double[] weights = {1,1,1,1,1,1,1,1};//{1,1,0.8,0.92,0.22};
        double optimalW=1;
        double p=0.5;
        double pmax=11;
        double starter=0;
        while(true){
            oldPrecision=newPrecision;
            for(int i =0;i<8;i++){
               out.println("Attribute# "+i);
                for(p=starter;p<pmax;){
                    knn.adjustWeight(i, p);
                    newPrecision=knn.crossValidate(186, 3, false, false);
                    if(newPrecision>oldPrecision){
                        oldPrecision = newPrecision;
                        optimalW=p;
                        weights[i]=p;
                    }
                    p+=0.2;
                }

                knn.setWeights(weights);
                newPrecision=knn.crossValidate(186, 3, false, false);
                out.println("----------------------------");
                p=0.2;
            }
            starter=pmax;
            pmax+=5;
            break;
        }


    }

    public static void bruteForce(String path, String trainProdSelData) throws IOException, CloneNotSupportedException{
        double oldPrecision, newPrecision;
        
        KNN_1 knn = new KNN_1();
        knn.loadTraining(path, trainProdSelData);
        knn.setOutputAttribute(7);
        newPrecision=knn.crossValidate(186, 3, false, false);

        int range = 1;
        int count = 0;

        out.println("TOTAL COUNT: "+count);
    }
}